#include "Scene1.h"
#include "BaseSprite.h"
#include "Global.h"
#include "GameLayerController.h"
#include "GameConstants.h"

USING_NS_CC;
Scene1::Scene1( cocos2d::CCScene *scene )
{
	this->sceneInstance=scene;
	this->gameController=GameLayerController::create();
}

Scene1::~Scene1(void)
{
	this->gameController->release();
}

void Scene1::RunScene()
{
	InitScene();
}

void Scene1::InitScene()
{
	//////////////////////////////////////////////////////////////////////////
	CCSize size = CCDirector::sharedDirector()->getWinSize();
	CCSprite* pSprite = CCSprite::create(s_scene_1_bg);	
	pSprite->setContentSize(CCSizeMake(size.width,size.height));
	// Place the sprite on the center of the screen
	pSprite->setPosition(ccp(size.width/2, size.height/2));

	// Add the sprite to HelloWorld layer as a child layer.
	this->gameController->addChild(pSprite, 0);

	//////////////////////////////////////////////////////////////////////////
	// hero
	//////////////////////////////////////////////////////////////////////////	
	BaseSprite *hero=BaseSprite::create();
	hero->spriteTag=SpriteTag::Hero;
	hero->InitFrameSet(1,8,"Hero_1_Right-%d.png",s_female_hero_Plist,SpriteAction::MoveRight);
	hero->InitFrameSet(1,8,"Hero_1_Right-%d.png",s_female_hero_Plist,SpriteAction::MoveLeft);
	hero->InitFrameSet(5,4,"Hero_1_Stand-%d.png",s_female_hero_Plist,SpriteAction::StandBy);
	hero->InitFrameSet(1,7,"Hero_1_Att-%d.png",s_female_hero_Plist,SpriteAction::Fight);
	hero->InitFrameSet(1,3,"Hero_1_Dead-%d.png",s_female_hero_Plist,SpriteAction::Dead);
	hero->SetCurrentAction(SpriteAction::StandBy);	
	hero->setPosition(ccp(size.width/3, size.height/3));
	this->gameController->addChild(hero,99);
	GameLayerController::hero=hero;
	//hero->retain();

	//////////////////////////////////////////////////////////////////////////
	//spider
	//////////////////////////////////////////////////////////////////////////
	for(int i=0;i<=3;i++)
	{
		BaseSprite *spider=BaseSprite::create();
		spider->spriteTag=SpriteTag::Enumy;
		spider->InitFrameSet(1,8,"Spider_Move-%d.png",s_spider_plist,SpriteAction::MoveLeft);
		spider->InitFrameSet(1,8,"Spider_Move-%d.png",s_spider_plist,SpriteAction::MoveRight);
		spider->InitFrameSet(1,14,"Spider_Att-%d.png",s_spider_plist,SpriteAction::Fight);
		spider->SetCurrentAction(SpriteAction::MoveLeft);
		spider->setPosition(ccp(size.width/3*2+i*100*CCRANDOM_0_1(), size.height/4));
		spider->setFlipX(true);
		spider->setScale(0.5);
		this->gameController->addChild(spider,1);
		GameLayerController::enumyArry->addObject(spider);	
	}	
	
	this->sceneInstance->addChild(this->gameController);
}
